home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group94b.txt / 000092_icon-group-sender _Fri Nov 4 11:19:05 1994.msg < prev    next >
Internet Message Format  |  1995-02-09  |  2KB

  1. Received: by cheltenham.cs.arizona.edu; Fri, 4 Nov 1994 12:45:55 MST
  2. Message-Id: <9411041819.AA11551@orpheus.gemini.edu>
  3. From: swampler@noao.edu
  4. Date: Fri, 4 Nov 1994 11:19:05 GMT+447
  5. X-Mailer: Mail User's Shell (7.2.3 5/22/91)
  6. To: icon-group@cs.arizona.edu
  7. Subject: A debugging hint...
  8. Content-Length: 1478
  9. Errors-To: icon-group-errors@cs.arizona.edu
  10.  
  11. This is a trick I use when debugging Icon code.  Maybe someone else
  12. will find it useful...
  13.  
  14. When trying to track down a bug in an Icon program, &trace does
  15. a nice job of showing the procedure calls and returns, including
  16. the line numbers.  Unfortunately, it doesn't help in sections of
  17. code where there are long stretches without any procedure calls.
  18.  
  19. A common method to 'trace' in those code stretches is to embed
  20. calls to 'write()', but then you have to do something to each
  21. call to disable them for runs without tracing, and put something
  22. into the argument list to each write to identify the line (&line
  23. is nice for that, incidently, etc.)
  24.  
  25. Let &trace work for you.  Create a procedure:
  26.  
  27. procedure Trace(s)
  28.    return
  29. end
  30.  
  31. and embed the calls to it where you would have put the write()s before:
  32.  
  33.     Trace(i)
  34.     ...
  35.     Trace("at start of loop")
  36.  
  37.     etc.
  38.  
  39. Now just run the program with &trace turned on.  Presto, you see
  40. a nice 'trace' showing the line numbers of the calls to Trace and
  41. the value of the argument.  Turn off &trace, and the debug output
  42. isn't shown.
  43.  
  44. If you want to see multiple values at each trace point, change
  45. the procedure to:
  46.  
  47. procedure Trace(s[])
  48.    return
  49. end
  50.  
  51. and now you can call it as:
  52.  
  53.     Trace("size of table is", *symbol_table)
  54.  
  55. I hope someone finds this useful.
  56.  
  57.  
  58. -- 
  59. Steve Wampler - swampler@gemini.edu [Gemini 8m Telescopes Project (under AURA)]
  60. --
  61. The Gods that were smiling when you were born are laughing now.
  62.                       -- found in a fortune cookie
  63.